<template>
  <div class="orderInfo flc w100p h100p oyauto oxhid">
    <van-form class="oyauto w100p flc" @submit="addOrder">
      <van-cell-group>
        <div class="title">订单信息</div>
        <van-field v-model="info.companyName" label="公司名称" :rules="[{ required: true, message: '请选择公司名称' }]">
          <template #input>
            <el-select v-model="info.companyName" placeholder="请选择" size="mini" class="w100p" @change="companyChange">
              <el-option v-for="item in companyList" :key="item.companyName" :label="item.companyName" :value="item.companyName" />
            </el-select>
          </template>
        </van-field>
        <van-field v-model="info.companySaleName" label="业务员" :rules="[{ required: true, message: '请选择业务员' }]">
          <template #input>
            <el-select v-model="info.companySaleName" placeholder="请选择" size="mini" class="w100p">
              <el-option v-for="item in saleList" :key="item.companySaleName" :label="item.companySaleName" :value="item.companySaleName" />
            </el-select>
          </template>
        </van-field>
        <van-field v-model="info.dateInput" readonly name="日期" label="日期" placeholder="请选择日期" @click="dataInputClick" />
        <van-field v-model="info.customerName" label="客户单位" :rules="[{ required: true, message: '请选择客户单位' }]">
          <template #input>
            <el-autocomplete v-model="info.customerName" size="mini" class="w100p" :fetch-suggestions="(qs, cb) => querySearch(qs, cb, customerList)" placeholder="请选择客户单位" @select="customerSelect" @change="customerChange" />
          </template>
        </van-field>
        <van-field v-model="info.customerAddress" name="地址" label="地址" placeholder="请输入地址" :rules="[{ required: true, message: '请输入地址' }]" @blur="customerAddressBlur" />
        <van-field v-model="info.customerPurchaserName" label="采购人" :rules="[{ required: true, message: '请输入采购人' }]">
          <template #input>
            <el-autocomplete v-model="info.customerPurchaserName" size="mini" class="w100p" :fetch-suggestions="(qs, cb) => querySearch(qs, cb, purchaserList)" placeholder="请选择采购人" @select="purchaserSelect" @change="purchaserChange" />
          </template>
        </van-field>
        <van-field v-model="info.customerPurchaserPhone" name="采购人电话" label="采购人电话" placeholder="请输入采购人电话" :rules="[{ required: true, message: '请输入采购人电话' }]" @blur="purchaserPhoneBlur" />
        <div class="title flb mt10">
          <div>
            <span>{{ '单品列表(' }}</span>
            <span class="cYE mr2 ml2 f14">{{ productList.length }}</span>
            <span>{{ ')' }}</span>
          </div>
          <van-icon name="plus" class="cYE l20" @click="addProduct" />
        </div>
        <div class="mt2">
          <div v-for="(item, idx) in productList" :key="idx">
            <van-swipe-cell :before-close="beforeClose">
              <van-field v-model="item.productBrandName" label="品牌" :rules="[{ required: true, message: '请选择品牌' }]">
                <template #input>
                  <el-autocomplete v-model="item.productBrandName" size="mini" class="w100p" :fetch-suggestions="(qs, cb) => querySearch(qs, cb, productBrandList)" placeholder="请选择品牌" @select="it => brandSelect(it, idx)" @change="str => brandChange(str, idx)" />
                </template>
              </van-field>
              <van-field v-model="item.productBrandArticleNo" label="货号" :rules="[{ required: true, message: '请选择货号' }]">
                <template #input>
                  <el-autocomplete v-model="item.productBrandArticleNo" size="mini" class="w100p" :fetch-suggestions="(qs, cb) => querySearch(qs, cb, item.goodsList)" placeholder="请选择货号" @select="it => articleNoSelect(it, idx)" @change="it => articleNoChange(it, idx)" />
                </template>
              </van-field>
              <van-field v-model="item.productBrandArticleNoName" label="单品名称" placeholder="请输入单品名称" :rules="[{ required: true, message: '请输入单品名称' }]" />
              <van-field v-model="item.productSpecificationName" label="规格" :rules="[{ required: true, message: '请选择规格' }]">
                <template #input>
                  <el-autocomplete v-model="item.productSpecificationName" size="mini" class="w100p" :fetch-suggestions="(qs, cb) => querySearch(qs, cb, specificateList)" placeholder="请选择规格" @change="it => specificateChange(it, idx)" @select="it => specificateSelect(it, idx)" />
                </template>
              </van-field>
              <van-field v-model="item.qty" type="number" label="数量" placeholder="请输入数量" :rules="[{ required: true, message: '请输入数量' }]" />
              <van-field v-model="item.unit" label="计量单位" :rules="[{ required: true, message: '请选择计量单位' }]">
                <template #input>
                  <el-select v-model="item.unit" placeholder="请选择" size="mini" class="w100p">
                    <el-option v-for="it in unitList" :key="it.unit" :label="it.unit" :value="it.unit" />
                  </el-select>
                </template>
              </van-field>
              <van-field v-model="item.purchaseSinglePrice" type="number" label="拿货单价" placeholder="请输入拿货单价" :rules="[{ required: true, message: '请输入拿货单价' }]" />
              <van-field v-model="item.customerSinglePrice" type="number" label="客户单价" placeholder="请输入客户单价" :rules="[{ required: true, message: '请输入客户单价' }]" />
              <van-field v-model="item.productSupplierName" label="供应商" :rules="[{ required: true, message: '请选择供应商' }]">
                <template #input>
                  <el-autocomplete v-model="item.productSupplierName" size="mini" class="w100p" :fetch-suggestions="(qs, cb) => querySearch(qs, cb, productSupplierList)" placeholder="请选择供应商" @change="it => productSupplierNameChange(it, idx)" @select="it => productSupplierNameSelect(it, idx)" />
                </template>
              </van-field>
              <van-field name="purchaseInvoice" label="进项票">
                <template #input>
                  <van-switch v-model="item.purchaseInvoice" size="20" active-color="#409eff" inactive-color="#dcdee0" />
                </template>
              </van-field>
              <van-field v-model="item.invoiceNo" label="发票号" disabled placeholder="请到订单列表中输入发票号" />
              <van-field label="是否回款">
                <template #input>
                  <van-switch v-model="item.purchaseInvoiceReceive" size="20" active-color="#409eff" inactive-color="#dcdee0" />
                </template>
              </van-field>
              <van-field v-model="item.remark" rows="3" autosize label="备注" type="textarea" maxlength="50" placeholder="请输入备注" />
              <template v-if="productList.length !== 1" #right>
                <van-button square type="danger" text="删除" class="h100p" @click.stop="delProduct(idx)" />
              </template>
            </van-swipe-cell>
          </div>
        </div>
      </van-cell-group>
      <div class="submitFooter">
        <van-button color="#409eff" round block type="primary" native-type="submit">新建订单</van-button>
      </div>
    </van-form>
    <van-popup v-model="dateShow" round position="bottom">
      <van-datetime-picker v-model="date" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate" @cancel="dateShow = false" @confirm="onConfirmTime" />
    </van-popup>
  </div>
</template>
<script>
import { addCustomer, updateCustomer, addPurchaser, updatePurchaser, getAllPurchaserByCustomerId, addProductBrand, addProductBrandArticleNo, addProductSpecification, addProductSupplier, getAllCompany, getAllCompanySaleByCompanyId, getAllCustomer, getAllProductBrand, getAllProductBrandArticleNoByProductBrandId, getAllProductSpecification, getAllUnit, getAllProductSupplier, addSaleOrder } from '../utils/api';
import moment from 'moment';
import pinyin from 'js-pinyin';
export default {
  data() {
    return {
      companyList: [],
      saleList: [],
      purchaserList: [],
      customerList: [], //客户单位
      dateShow: false,
      info: {
        customerFirst: false,
        customerUpdate: false, //修改客户地址标记
        customerId: undefined,
        companyName: undefined,
        companySaleName: undefined,
        customerName: undefined,
        customerAddress: undefined,
        purchaserFirst: false,
        purchaserUpdate: false, //修改客户采购人电话标记
        customerPurchaserName: undefined,
        customerPurchaserPhone: undefined
      },
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2030, 10, 1),
      date: undefined,
      productList: [], //可多个， 字段如下
      productBrandList: [], //品牌
      instance: undefined, //单品的删除示例
      goodsNoList: [], //单品货号
      specificateList: [], //规格
      productSupplierList: [], //供应商
      unitList: [] //计量单位
    };
  },
  mounted() {
    this.$set(this.info, 'dateInput', moment().format('YYYY-MM-DD'));
    this.addProduct();
    this.getAllCompany();
    this.getCustomerList();
    this.getProductBrandList();
    this.getProductSpecificationList();
    this.getUnitList();
    this.getProductSupplierList();
  },
  methods: {
    getPingyin(name) {
      return pinyin.getCamelChars(name);
    },
    //公司列表
    async getAllCompany() {
      let res = await getAllCompany();
      this.companyList = [];
      res.data.forEach(el => {
        el.sort = this.getPingyin(el.companyName);
      });
      res.data.sort((a, b) => a.sort.localeCompare(b.sort));
      res.data.forEach(el => {
        this.companyList.push({ ...el, value: el.companyName });
      });
    },
    //客户列表
    async getCustomerList() {
      let res = await getAllCustomer();
      this.customerList = [];
      res.data.forEach(el => {
        el.sort = this.getPingyin(el.customerName);
      });
      res.data.sort((a, b) => a.sort.localeCompare(b.sort));
      res.data.forEach(el => {
        this.customerList.push({ ...el, value: el.customerName });
      });
    },
    //品牌列表
    async getProductBrandList() {
      let res = await getAllProductBrand();
      this.productBrandList = [];
      res.data.forEach(el => {
        el.sort = this.getPingyin(el.productBrandName);
      });
      res.data.sort((a, b) => a.sort.localeCompare(b.sort));
      res.data.forEach(el => {
        this.productBrandList.push({ ...el, value: el.productBrandName });
      });
    },
    //规格列表
    async getProductSpecificationList() {
      let res = await getAllProductSpecification();
      this.specificateList = [];
      res.data.forEach(el => {
        el.sort = this.getPingyin(el.productSpecificationName);
      });
      res.data.sort((a, b) => a.sort.localeCompare(b.sort));
      res.data.forEach(el => {
        this.specificateList.push({ ...el, value: el.productSpecificationName });
      });
    },
    //计量单位列表
    async getUnitList() {
      let res = await getAllUnit();
      this.unitList = res.data;
    },
    //供应商列表
    async getProductSupplierList() {
      let res = await getAllProductSupplier();
      this.productSupplierList = [];
      res.data.forEach(el => {
        el.sort = this.getPingyin(el.productSupplierName);
      });
      res.data.sort((a, b) => a.sort.localeCompare(b.sort));
      res.data.forEach(el => {
        this.productSupplierList.push({ ...el, value: el.productSupplierName });
      });
    },
    querySearch(queryString, cb, list) {
      let results = queryString ? list.filter(this.createFilter(queryString)) : list;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return data => {
        return data.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0;
      };
    },
    //选择公司
    async companyChange() {
      let idx = this.companyList.findIndex(item => item.companyName === this.info.companyName);
      let res = await getAllCompanySaleByCompanyId({ companyId: this.companyList[idx].id });
      this.saleList = res.data;
      this.info.companySaleName = undefined;
    },
    //日期点击
    dataInputClick() {
      this.date = new Date(moment().year(), moment().month(), moment().format('DD'));
      this.dateShow = true;
    },
    //日期框确认
    onConfirmTime(time) {
      this.info.dateInput = moment(time).format('YYYY-MM-DD');
      this.dateShow = false;
    },
    //选择客户，自动填写采购人、电话、地址
    async customerSelect(item) {
      this.info.customerFirst = false;
      this.info.customerUpdate = false;
      this.info.customerId = item.id;
      this.info.customerAddress = item.customerAddress;
      let res = await getAllPurchaserByCustomerId({ customerId: item.id });
      this.purchaserList = [];
      res.data.forEach(el => {
        this.purchaserList.push({ ...el, value: el.customerPurchaserName });
      });
      this.info.customerPurchaserName = undefined;
      this.info.customerPurchaserPhone = undefined;
    },
    //手输客户，匹配到自动填写采购人、电话、地址，没匹配到清空
    async customerChange(str) {
      if (str) {
        this.info.customerFirst = false;
        this.info.customerUpdate = false;
        let idx = this.customerList.findIndex(item => item.customerName === str);
        if (idx === -1) {
          this.info.customerFirst = true;
          this.info.customerPurchaserName = undefined;
          this.info.customerPurchaserPhone = undefined;
          this.info.customerAddress = undefined;
        } else {
          this.info.customerAddress = this.customerList[idx].customerAddress;
          let res = await getAllPurchaserByCustomerId({ customerId: this.customerList[idx].id });
          this.purchaserList = [];
          res.data.forEach(el => {
            this.purchaserList.push({ ...el, value: el.customerPurchaserName });
          });
        }
      }
    },
    //客户地址失焦
    customerAddressBlur() {
      let idx = this.customerList.findIndex(item => item.customerAddress === this.info.customerAddress);
      if (idx === -1 && !this.customerFirst) {
        this.info.customerUpdate = true;
      }
    },
    //采购人选择
    purchaserSelect(item) {
      this.info.purchaserFirst = false;
      this.info.purchaserUpdate = false;
      this.info.customerPurchaserPhone = item.customerPurchaserPhone;
    },
    //采购人手动改变
    purchaserChange(str) {
      if (str) {
        this.info.purchaserFirst = false;
        this.info.purchaserUpdate = false;
        let idx = this.purchaserList.findIndex(item => item.customerPurchaserName === str);
        if (idx === -1) {
          this.info.purchaserFirst = true;
          this.info.customerPurchaserPhone = undefined;
        } else {
          this.info.customerPurchaserPhone = this.purchaserList[idx].customerPurchaserPhone;
        }
      }
    },
    //客户号码失焦
    purchaserPhoneBlur() {
      let idx = this.purchaserList.findIndex(item => item.customerPurchaserPhone === this.info.customerPurchaserPhone);
      if (idx === -1 && !this.purchaserFirst) {
        this.info.purchaserUpdate = true;
      }
    },
    //新增单品
    addProduct() {
      this.productList.push({
        productBrandId: undefined,
        productBrandFirst: false,
        productBrandName: undefined,
        productBrandArticleNoFirst: false,
        productBrandArticleNo: undefined,
        productSpecificationNameFirst: false,
        productSpecificationName: undefined,
        productBrandArticleNoNameFirst: false,
        productBrandArticleNoName: undefined,
        unit: '',
        qty: 1,
        purchaseSinglePrice: undefined,
        customerSinglePrice: undefined,
        productSupplierName: undefined,
        productSupplierNameFirst: false,
        purchaseInvoice: false,
        invoiceNo: undefined,
        purchaseInvoiceReceive: false,
        remark: undefined,
        goodsList: []
      });
    },
    //删除单品
    async delProduct(idx) {
      await this.$async.confirm({ message: '确认要删除单品信息吗？' });
      this.productList.splice(idx, 1);
    },
    //删除单品
    beforeClose({ instance }) {
      this.instance = instance;
    },
    //选择品牌
    async brandSelect(item, index) {
      this.productList[index].productBrandId = undefined; //品牌
      this.productList[index].productBrandFirst = false; //品牌
      this.productList[index].productBrandArticleNo = undefined; //货号
      this.productList[index].productBrandArticleNoFirst = false; //货号
      this.productList[index].productBrandArticleNoName = undefined;
      this.productList[index].productBrandArticleNoNameFirst = false;
      this.productList[index].productSpecificationName = undefined; //规格
      this.productList[index].productSpecificationNameFirst = false; //规格
      this.productList[index].unit = undefined;
      this.productList[index].qty = 1;
      this.productList[index].purchaseSinglePrice = undefined;
      this.productList[index].customerSinglePrice = undefined;
      this.productList[index].productSupplierName = undefined;
      this.productList[index].productSupplierNameFirst = false;
      this.productList[index].purchaseInvoice = false;
      this.productList[index].invoiceNo = undefined;
      this.productList[index].purchaseInvoiceReceive = false;
      this.productList[index].remark = undefined;
      this.productList[index].goodsList = [];
      let res = await getAllProductBrandArticleNoByProductBrandId({ productBrandId: item.id });
      this.productList[index].productBrandId = item.id;
      res.data.forEach(el => {
        this.productList[index].goodsList.push({ ...el, value: el.productBrandArticleNo });
      });
    },
    //改变品牌
    async brandChange(str, index) {
      if (str) {
        let idx = this.productBrandList.findIndex(item => item.productBrandName === str);
        this.productList[index].productBrandId = undefined; //品牌
        this.productList[index].productBrandFirst = false; //品牌
        this.productList[index].productBrandArticleNo = undefined; //货号
        this.productList[index].productBrandArticleNoFirst = false; //货号
        this.productList[index].productBrandArticleNoName = undefined;
        this.productList[index].productBrandArticleNoNameFirst = false;
        this.productList[index].productSpecificationName = undefined; //规格
        this.productList[index].productSpecificationNameFirst = false; //规格
        this.productList[index].unit = undefined;
        this.productList[index].qty = 1;
        this.productList[index].purchaseSinglePrice = undefined;
        this.productList[index].customerSinglePrice = undefined;
        this.productList[index].productSupplierName = undefined;
        this.productList[index].productSupplierNameFirst = false;
        this.productList[index].purchaseInvoice = false;
        this.productList[index].invoiceNo = undefined;
        this.productList[index].purchaseInvoiceReceive = false;
        this.productList[index].remark = undefined;
        this.productList[index].goodsList = [];
        if (idx === -1) {
          this.productList[index].productBrandFirst = true;
        } else {
          let res = await getAllProductBrandArticleNoByProductBrandId({ productBrandId: this.productBrandList[idx].id });
          this.productList[index].productBrandId = this.productBrandList[idx].id;
          res.data.forEach(el => {
            this.productList[index].goodsList.push({ ...el, value: el.productBrandArticleNo });
          });
        }
      }
    },
    //选择货号
    articleNoSelect(item, index) {
      this.productList[index].productBrandArticleNoFirst = false;
      this.productList[index].productBrandArticleNoNameFirst = false;
      this.productList[index].productBrandArticleNoName = item.productBrandArticleNoName;
    },
    //改变货号
    articleNoChange(str, index) {
      if (str) {
        this.productList[index].productBrandArticleNoFirst = false;
        this.productList[index].productBrandArticleNoNameFirst = false;
        let idx = this.productList[index].goodsList.findIndex(item => item.productBrandArticleNo === str);
        if (idx === -1) {
          this.productList[index].productBrandArticleNoFirst = true;
        } else {
          this.productList[index].productBrandArticleNoName = this.productList[index].goodsList[idx].productBrandArticleNoName;
        }
      }
    },
    //改变规格
    specificateChange(str, index) {
      if (str) {
        this.productList[index].productSpecificationNameFirst = false;
        let idx = this.productList[index].goodsList.findIndex(item => item.productSpecificationName === str);
        if (idx === -1) {
          this.productList[index].productSpecificationNameFirst = true;
        }
      }
    },
    //选择规格
    specificateSelect(str, index) {
      let idx = this.productSupplierList.findIndex(el => el.productSpecificationName === str);
      if (idx !== -1) {
        this.productList[index].productSpecificationNameFirst = true;
      }
    },
    //改变供应商
    productSupplierNameChange(str, index) {
      if (str) {
        this.productList[index].productSupplierNameFirst = false;
        let idx = this.productSupplierList.findIndex(item => item.productSupplierName === str);
        if (idx === -1) {
          this.productList[index].productSupplierNameFirst = true;
        }
      }
    },
    //选择供应商
    productSupplierNameSelect(str, index) {
      let idx = this.productSupplierList.findIndex(el => el.productSupplierName === str);
      if (idx !== -1) {
        this.productList[index].productSupplierNameFirst = true;
      }
    },
    //新增订单
    async addOrder() {
      await this.addInfo();
      let list = JSON.parse(JSON.stringify(this.productList));
      list.forEach(item => {
        item.purchaseInvoice = item.purchaseInvoice ? '1' : '2';
        item.purchaseInvoiceReceive = item.purchaseInvoiceReceive ? '1' : '2';
        delete item.goodsList;
      });
      let data = { ...this.info, addList: list };
      await addSaleOrder(data);
      this.$toast({ type: 'success', message: '新增订单成功' });
      this.reset();
      await this.$async.delay(2000);
      uni.postMessage({ data: '/pages/home/orderList' }); //eslint-disable-line
    },
    // 将不存在的信息添加的信息维护中去
    async addInfo() {
      let data = JSON.parse(JSON.stringify(this.info));
      for (let i = 1; i < data.length; i++) {
        for (let j = 0; j < i; j++) {
          if (this.productList[i].productBrandName === this.productList[j].productBrandName && this.productList[i].productBrandArticleNo === this.productList[j].productBrandArticleNo) {
            this.productList[i].productBrandArticleNoName = this.productList[j].productBrandArticleNoName;
          }
        }
      }
      let axiosList = [];
      //强制更改品牌一样货号一样下的名称不一样为一样
      //新增客户
      if (data.customerFirst) {
        addCustomer({ ...data });
      } else if (data.customerUpdate) {
        updateCustomer({ ...data });
      } else if (data.purchaserFirst) {
        addPurchaser({ ...data });
      } else if (data.purchaserUpdate) {
        updatePurchaser({ ...data });
      }
      let hasBrandList = [];
      let hasSpecificationList = [];
      let hasSupplierList = [];
      this.productList.forEach(async (item, num) => {
        //新增品牌
        if (item.productBrandFirst) {
          if (hasBrandList.length === 0 || hasBrandList.findIndex(el => el === item.productBrandName) === -1) {
            hasBrandList.push(item.productBrandName);
            let res = await addProductBrand({ productBrandName: item.productBrandName });
            this.productList[num].brandInfo = { id: res.data, name: item.productBrandName };
            //新增品牌时新增单品：货号、名称
            await addProductBrandArticleNo({ productBrandArticleNo: item.productBrandArticleNo, productBrandArticleNoName: item.productBrandArticleNoName, productBrandId: res.data });
            //查询品牌下新增的货号
            let res1 = await getAllProductBrandArticleNoByProductBrandId({ productBrandId: res.data });
            this.productList[num].goodsList = [];
            res1.data.forEach(el => {
              this.productList[num].goodsList.push({ ...el, value: el.productBrandArticleNo });
            });
          } else if (hasBrandList.findIndex(el => el === item.productBrandName) !== -1) {
            //品牌相同，货号不存在数据库里，但跟之前货号相同时
            if (item.productBrandArticleNoFirst) {
              //查询之前已经新增数据库的数据
              let idx = this.productList.findIndex(el => el.productBrandName === item.productBrandName && el.productBrandId);
              //存在相同货号
              let n = this.productList[idx].goodsList.findIndex(el => el.productBrandArticleNo === item.productBrandArticleNo);
              if (n === -1) {
                await addProductBrandArticleNo({ productBrandArticleNo: item.productBrandArticleNo, productBrandArticleNoName: item.productBrandArticleNoName, productBrandId: this.productList[idx].productBrandId });
                //查询品牌下新增的货号
                let res1 = await getAllProductBrandArticleNoByProductBrandId({ productBrandId: this.productList[idx].productBrandId });
                this.productList[idx].goodsList = [];
                res1.data.forEach(el => {
                  this.productList[idx].goodsList.push({ ...el, value: el.productBrandArticleNo });
                });
              }
            }
          }
        }
        //已有品牌新增单品
        if (!item.productBrandFirst && item.productBrandArticleNoFirst) {
          await addProductBrandArticleNo({ productBrandArticleNo: item.productBrandArticleNo, productBrandArticleNoName: item.productBrandArticleNoName, productBrandId: item.productBrandId });
          let res1 = await getAllProductBrandArticleNoByProductBrandId({ productBrandId: item.productBrandId });
          res1.data.forEach(el => {
            this.productList[num].goodsList.push({ ...el, value: el.productBrandArticleNo });
          });
        }
        //新增规格
        if (item.productSpecificationNameFirst) {
          if (hasSpecificationList.length === 0 || hasSpecificationList.findIndex(el => el === item.productSpecificationName) === -1) {
            await addProductSpecification({ productSpecificationName: item.productSpecificationName });
            hasSpecificationList.push(item.productSpecificationName);
          }
        }
        //新增供应商
        if (item.productSupplierNameFirst) {
          if (hasSupplierList.length === 0 || hasSupplierList.findIndex(el => el === item.productSupplierName) === -1) {
            await addProductSupplier({ productSupplierName: item.productSupplierName });
            hasSupplierList.push(item.productSupplierName);
          }
        }
      });
      await this.$axiosAll(axiosList);
    },
    //恢复默认值
    reset() {
      this.info = { customerFirst: false, customerUpdate: false, customerId: undefined, companyName: undefined, companySaleName: undefined, customerName: undefined, purchaserFirst: false, purchaserUpdate: false, customerPurchaserName: undefined, customerPurchaserPhone: undefined, customerAddress: undefined, dateInput: moment().format('YYYY-MM-DD') };
      this.productList = [];
      this.productList.push({ productBrandId: undefined, productBrandFirst: false, productBrandName: undefined, productBrandArticleNoFirst: false, productBrandArticleNo: undefined, productBrandArticleNoName: undefined, productSpecificationNameFirst: false, productSpecificationName: undefined, productBrandArticleNoNameFirst: false, unit: undefined, qty: 1, purchaseSinglePrice: undefined, customerSinglePrice: undefined, productSupplierName: undefined, productSupplierNameFirst: false, purchaseInvoice: false, invoiceNo: undefined, purchaseInvoiceReceive: false, remark: undefined, goodsList: [] });
      this.getAllCompany();
      this.getCustomerList();
      this.getProductBrandList();
      this.getProductSpecificationList();
      this.getUnitList();
      this.getProductSupplierList();
    }
  }
};
</script>
<style lang="less" scoped>
.orderInfo {
  .submitFooter {
    background: white;
    padding: 16px;
    box-sizing: border-box;
  }
}
</style>
